package ml;

import java.util.ArrayList;

import org.junit.Test;

import util.DataUtil;

import junit.framework.Assert;

public class TestAdaBoostTrainer {

	@Test
	/**
	 * 2  A A | B
	 * -------|---
	 * 1  B B | A
	 * -------|---
	 * 0  1 2 | 3
	 */
	public void test() {
		ArrayList<ArrayList<Double>> featuresBasedonFeature = new ArrayList<ArrayList<Double>>();
		ArrayList<Boolean> labels = new ArrayList<Boolean>();

		labels.add(true);
		labels.add(true);
		labels.add(true);
		labels.add(false);
		labels.add(false);
		labels.add(false);

		ArrayList<Double> x_feature = new ArrayList<Double>();
		x_feature.add(0.9);
		x_feature.add(1.9);
		x_feature.add(3.1);
		x_feature.add(1.1);
		x_feature.add(2.1);
		x_feature.add(2.9);
		featuresBasedonFeature.add(x_feature);

		ArrayList<Double> y_feature = new ArrayList<Double>();
		y_feature.add(1.9);
		y_feature.add(2.1);
		y_feature.add(1.0);
		y_feature.add(1.1);
		y_feature.add(0.9);
		y_feature.add(2.0);
		featuresBasedonFeature.add(y_feature);

		ArrayList<ArrayList<Double>> featuresBasedonSample = DataUtil
						.Transpose(featuresBasedonFeature);

		StrongClassifer strongClassifier = AdaBoostTrainer.trainStrong(featuresBasedonFeature,
						labels, 10, featuresBasedonSample);

		for (int i = 0; i < labels.size(); ++i) {
			Assert.assertTrue(labels.get(i).equals(
							strongClassifier.judge(featuresBasedonSample.get(i))));
		}
	}

}
